package com.kermel.andromeda.engine.view;

import android.widget.TextView;

import com.kermel.andromeda.clock.format.CurrentTimeFormatter;

public class CurrentTimeViewUpdater implements Runnable {
    private TextView clockView;
    private CurrentTimeFormatter formatter;
    private long currentTime;
    
    public CurrentTimeViewUpdater(TextView clockView, CurrentTimeFormatter formatter) {
        this.clockView = clockView;
        this.formatter = formatter;
    }
    
    public void updateCurrentTime(long currentTime) {
        this.currentTime = currentTime;
        if (clockView != null) {
            clockView.post(this);
        }
    }
    
    public void run() {
        if (clockView != null) {
            CharSequence message = formatCurrentTimeAsString(currentTime);
            clockView.setText(message);
        }
    }
    
    public CharSequence formatCurrentTimeAsString(long currentTime) {
        return formatter.formatTimeAsString(currentTime);
    }
}
